//
//  MainTabBarViewController.swift
//  ZBWb
//
//  Created by 天隐翎 on 16/4/6.
//  Copyright © 2016年 csdn. All rights reserved.
//

import UIKit

class MainTabBarViewController: UITabBarController {
    
    @objc private func didbuttonclick(){
    
//    print("hahhah")
    
    }

    override func viewDidLoad() {
        super.viewDidLoad()
//        自定义tabBar
        let newtabBar = NewtabBar()
//        添加点击事件
        newtabBar.newbut.addTarget(self, action: "didbuttonclick", forControlEvents: .TouchUpInside)
        
//        用KVC进行替换
//        print(tabBar.classForCoder)
        setValue(newtabBar, forKey: "tabBar")
        
//        print(tabBar.classForCoder)
        
        
//        添加控制器的函数
        addchildViewControllers()

    }
    
//    添加自控制器
    func addchildViewControllers() {
        addChildViewsController(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewsController(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewsController(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewsController(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
    }
//    添加子控制器封装
    func addChildViewsController(childController: UIViewController,title: String,imageName:String) {
        childController.tabBarItem.title = title
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName :UIColor.orangeColor()], forState: .Selected)
        childController.tabBarItem.image = UIImage(named: imageName)
        childController.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
//        设置每个标题
        childController.navigationItem.title = title
//        创建导航控制器
        let nav = ZBNavifationController(rootViewController: childController)
        
//        添加到tabbar控制器
//        addChildViewController(childController)
        addChildViewController(nav)
        
    }
    

}
